using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Common.Pool
{
    public class ObjectPoolCompoent : MonoBehaviour
    {
        private ObjectPoolManager poolManager;
        public static ObjectPoolCompoent Instance;
        private void Awake()
        {
            poolManager = new ObjectPoolManager();
            Instance = this;
        }
        public ObjectPool<T> CreatPool<T>(PoolObject<T> obj, string poolName) where T : class
        {
            return (ObjectPool<T>)poolManager.CreatePool<T>(obj, poolName);
        }
        public bool TryGetPool<T>(string poolName, out ObjectPool<T> res) where T : class
        {

            if ((ObjectPool<T>)poolManager.GetPool<T>(poolName) != null)
            {
                res = (ObjectPool<T>)poolManager.GetPool<T>(poolName);
                return true;
            }
            else
            {
                res = null;
                return false;
            }
        }
        public void DestoryPool<T>(string poolName)
        {
            poolManager.DestoryPool<T>(poolName);
        }
    }
}